package com.itheima.test3;

import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Constructor;

/**
 * @Author:gy
 * @Date: 2025/09/06 10:23
 * @Description:
 */
public class Demo1 {
    Class  clazz;
    @Before
    public void getClass1() throws Exception {
        clazz = Class.forName("com.itheima.test3.Student");
    }
    @Test
    public void method1(){
        //获取所有公共的构造方法  不包括私有
        Constructor[] constructors = clazz.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }
    @Test
    public void method2(){
        //获取所有的构造方法 包括私有
        Constructor[] dc = clazz.getDeclaredConstructors();
        for (Constructor constructor : dc) {
            System.out.println(constructor);
        }
    }
    @Test
    public void method3() throws Exception {
        Constructor constructor = clazz.getConstructor(String.class, int.class);
        System.out.println(constructor);
    }
    @Test
    public void method4() throws Exception {
        //返回公共的
        Constructor constructor = clazz.getConstructor();
        System.out.println(constructor);
    }
    @Test
    public void method5() throws Exception {
        Constructor constructor = clazz.getDeclaredConstructor(String.class);
        System.out.println(constructor);
    }
}
